<?php

namespace app\admin\model\dealer;

use think\Model;
use traits\model\SoftDelete;

class Dealer extends Model
{

    use SoftDelete;

    

    // 表名
    protected $name = 'dealer';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [

    ];

    public function getDealerTypeList()
    {
        return ['0' => __('DealerType 0'), '1' => __('DealerType 1')];
    }

    /**
     * 获取经销商列表
     * @param array $where
     * @param string $order
     * @return array
     */
    public function dealerList($where = []){
        $dealerlist = $this->where($where)->column('name', 'id');
        return $dealerlist;
    }

    /**
     * 获取经销商余额
     * @param int $id
     * @return float|int|mixed
     */
    public function getDealerUsermoney($id = 0){
        if($id == 0){
            //所有经销商余额
            $usermoney = $this->sum('usermoney');
        }else{
            //某个经销商余额
            $usermoney = $this->where(array('id'=>$id))->value('usermoney');
        }
        return $usermoney;
    }
}
